package com.djl.rabbitmq.seven;

import com.djl.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: rabbitmq-hello
 * @description:
 * @author: Mr.dai
 * @create: 2021-09-12 20:27
 **/

public class EmitLogTopic {
    public static  final  String EXCHANGE_NAME ="topic_logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        Map<String,String> bindingKingMap=new HashMap<>();

                //quick.orange.fox 被队列 Q1 接收到
                //lazy.brown.fox 被队列 Q2 接收到
                //lazy.pink.rabbit 虽然满足两个绑定但只被队列 Q2 接收一次
                //quick.brown.fox 不匹配任何绑定不会被任何队列接收到会被丢弃
                //quick.orange.male.rabbit 是四个单词不匹配任何绑定会被丢弃
                //lazy.orange.male.rabbit 是四个单词但匹配 Q2
        bindingKingMap.put("quick.orange.fox","被队列 Q1 接收到");
        bindingKingMap.put("lazy.brown.fox","被队列 Q2 接收到");
        bindingKingMap.put("lazy.pink.rabbit"," 虽然满足两个绑定但只被队列 Q2 接收一次");
        bindingKingMap.put("quick.brown.fox","不匹配任何绑定不会被任何队列接收到会被丢弃");
        bindingKingMap.put("quick.orange.male.rabbit","是四个单词不匹配任何绑定会被丢弃");
        bindingKingMap.put("lazy.orange.male.rabbit","是四个单词但匹配 Q2");
        for (Map.Entry<String,String> bindingKeyEntry : bindingKingMap.entrySet()){
            String bindkey=bindingKeyEntry.getKey();
            String msg=bindingKeyEntry.getValue();
            channel.basicPublish(EXCHANGE_NAME,bindkey,null,msg.getBytes(StandardCharsets.UTF_8));
            System.out.println("生产者发出消息："+msg);
        }
    }
}
